from typing import Optional
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy_crud_plus import CRUDPlus

from modules.customer_info.models.customer_info_model import CustomerInfo
from modules.customer_info.schemas.customer_info_schema import CustomerInfoCreate, CustomerInfoUpdate
from modules.customer_info.params.customer_info_params import CustomerInfoQuery


class CustomerInfoRepository(CRUDPlus[CustomerInfo]):

    async def get_by_id(self, db: AsyncSession, pk: int):
        return await self.select_model_by_column(db, id=pk)

    async def create(self, db: AsyncSession, data: CustomerInfoCreate) -> CustomerInfo:
        return await self.create_model(db, data)

    async def update(self, db: AsyncSession, pk: int, data: CustomerInfoUpdate) -> Optional[CustomerInfo]:
        await self.update_model(db, pk, data)
        return await self.select_model(db, pk)

    async def delete(self, db: AsyncSession, pk: int) -> bool:
        return await self.delete_model(db, pk)


customer_info_dao = CustomerInfoRepository(CustomerInfo)